package com.siwen.controller;

import com.siwen.api.ApiResult;
import com.siwen.service.ChildService;
import com.siwen.pojo.ChildTbl;
import com.siwen.util.ResultUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@CrossOrigin
public class ChildController {

    @Resource
    private ChildService childService;

    /**
     * 查询所有儿童
     * @return
     */
    @RequestMapping("/getChilds")
    @ResponseBody
    public List<ChildTbl> getChildInfo(){
        List<ChildTbl> childInfo = childService.getChildInfo();
        return childInfo;
    }

    /**
     * 登录
     * @param username
     * @param password
     * @param session
     * @return
     */
    @RequestMapping("/ChildLogin")
    @ResponseBody
    public ApiResult<String> ChildLogin(@RequestParam String username,@RequestParam String password, HttpSession session){
        ChildTbl childTbl=null;
        childTbl=childService.ChildLogin(username,password);
        return ResultUtil.success(childTbl);
    }

    /**
     * 注册
     * @param child
     * @return
     */
    @RequestMapping("/getinsertChild")
    @ResponseBody
    public int insertChild(ChildTbl child) {
        ChildTbl chi = new ChildTbl();
        chi.setChildid("10005");
        chi.setUsername("june");
        chi.setPassword("12345678");
        int result = childService.insertChild(chi);

        System.out.print(result);
        if (result>0){
            System.out.print("添加成功");
        }else{
            System.out.print("添加失败");
        }
        return result;
    }
}
